package com.company.admin.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author 赵成林
 * @date 2019/2/17 11:58
 */
@Configuration
public class WebAppConfig extends WebMvcConfigurerAdapter {
    @Value("${my.upload.imgPath}")
    private String imgPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String staticMapping = "/image/**";
        String localDirectory = "file:" + imgPath;
//        System.out.println(imgPath);
        registry.addResourceHandler(staticMapping).addResourceLocations(localDirectory);
        super.addResourceHandlers(registry);
    }
}
